#ifndef FAN_H
#define FAN_H

#include <QWidget>
#include "TableWidgetForm.h"

struct FanConnectStr
{
    QString name;
    QString type;

    // 获取结构体成员名的字符串
    QString toFieldNames() const {
        return QString("name,type");
    }

    // 获取结构体成员名的字符串
    QStringList toFieldTypes() const {
        QStringList _list;
        _list << typeid(name).name();
        _list << typeid(type).name();
        return _list;
    }
};

struct Fanstruct
{
    int id;
    QString name;
    int rotate;
    int maxrotate;
    int uplimit;
    int lowlimit;
    int board_id;
    int phyid;
    int enable;
    QString location;
    QString phymap;

    // 获取结构体成员名的字符串
    QString toFieldNames() const {
        return QString("name,rotate,maxrotate,uplimit,lowlimit,board_id,phyid,"
                       "enable,location,phymap");
    }

    // 获取结构体成员名的字符串
    QStringList toFieldTypes() const {
        QStringList _list;
        _list << typeid(name).name();
        _list << typeid(rotate).name();
        _list << typeid(maxrotate).name();
        _list << typeid(uplimit).name();
        _list << typeid(lowlimit).name();
        _list << typeid(board_id).name();
        _list << typeid(phyid).name();
        _list << typeid(enable).name();
        _list << typeid(location).name();
        _list << typeid(phymap).name();
        return _list;
    }
};

class Fan
{
public:
    Fan();

    //初始化UI
    static void InitUI(const QString& fileName, QList<QPair<QWidget *, QString>>& widgets, QMap<int, QList<TableWidgetForm*>>& m_pTableWidgetFormMap);

    //保存
    static bool SaveUI(const QString& fileName, const QMap<int, QList<TableWidgetForm*>>& m_pTableWidgetFormMap);

    //解析
    static void Analysis(const QString& path, FanConnectStr& _FanConnectStr, QList<QList<Fanstruct>>& FanstructList);

    //保存
    static bool SaveXml(const QString& path, const FanConnectStr& _FanConnectStr, const QList<QList<Fanstruct>>& FanstructList);
};

#endif // FAN_H
